/**
 * @file:     test.c
 * @Author:   ChenBlue
 * @email:    ChenBlue952@qq.com
 * @data:     Tue Jan 31 02:18:57 2023
 * @brief:
 */

#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

void main(int argc, char* argv[])
{
	char buf[1];
	int fd = open("/dev/leds", O_RDWR);
	if (fd < 0) {
		printf("open /dev/leds fail");
		return;
	}

	switch (*argv[1]) {
	case 'r':
		read(fd, buf, 1);
		printf("led value is %d\n", buf[0]);
		break;
	case 'w':
		switch (*argv[2]) {
		case '0':
			buf[0] = 0;
			break;
		case '1':
			buf[0] = 1;
			break;
		default:
			break;
		}
		if (write(fd, buf, 1)) {
			printf("write fail");
			return;
		}
		break;
	default:
		printf("please r or w \n");
		break;
	}
	close(fd);
}